package com.damocode.starter.httpclient.domain;

import com.damocode.starter.httpclient.helper.FormatType;

import java.util.HashMap;
import java.util.Map;

public class HttpResponse {

    private int statusCode;

    private String reasonPhrase;

    protected String responseText = null;

    protected String encoding = null;

    protected FormatType contentType = null;

    protected Map<String, String> headers = new HashMap();

    public void setContent(String responseText, String encoding, FormatType format) {
        this.responseText = responseText;
        this.encoding = encoding;
        this.contentType = format;
    }

    public void putHeaderParameter(String name, String value) {
        if (null != name && null != value) {
            this.headers.put(name, value);
        }
    }

    public String getHeaderValue(String name) {
        String value = this.headers.get(name);
        if (null == value) {
            value = this.headers.get(name.toLowerCase());
        }
        return value;
    }

    public boolean isSuccess() {
        return 200 <= this.statusCode && this.statusCode < 300;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public String getReasonPhrase() {
        return reasonPhrase;
    }

    public void setReasonPhrase(String reasonPhrase) {
        this.reasonPhrase = reasonPhrase;
    }

    public String getResponseText() {
        return responseText;
    }

    public void setResponseText(String responseText) {
        this.responseText = responseText;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public FormatType getContentType() {
        return contentType;
    }

    public void setContentType(FormatType contentType) {
        this.contentType = contentType;
    }
}
